package com.um.jdy.ykc.command;

import com.um.jdy.ykc.utils.RadixsUtil;
import com.um.jdy.ykc.utils.YkcTimeUtil;
import lombok.Data;

import java.util.Date;

/**
 * 交易记录（充电桩->运营平台）
 *
 * @author 甘天伟
 * @since 2022/6/28
 * 版权所有 广州优匠科技有限公司
 */
@Data
public class Cmd3BUploadOrderRequest extends YkcCommand {
    /**
     * 交易流水号：16个字节
     */
    private String transactionNo;

    /**
     * 桩编码：7个字节
     */
    private String code;

    /**
     * 枪号：1个字节
     */
    private int gunNo;

    /**
     * 开始时间：7个字节
     */
    private Date beginTime;

    /**
     * 结束时间：7个字节
     */
    private Date endTime;

    /**
     * 尖单价：4个字节
     */
    private int sharpPrice;

    /**
     * 尖电量：4个字节
     */
    private int sharpCapacity;

    /**
     * 计损尖电量：4个字节
     */
    private int sharpLossCapacity;

    /**
     * 尖金额：4个字节
     */
    private int sharpAmount;

    /**
     * 峰单价：4个字节
     */
    private int peakPrice;

    /**
     * 峰电量：4个字节
     */
    private int peakCapacity;

    /**
     * 计损峰电量：4个字节
     */
    private int peakLossCapacity;

    /**
     * 峰金额：4个字节
     */
    private int peakAmount;

    /**
     * 平单价：4个字节
     */
    private int shoulderPrice;

    /**
     * 平电量：4个字节
     */
    private int shoulderCapacity;

    /**
     * 计损平电量：4个字节
     */
    private int shoulderLossCapacity;

    /**
     * 平金额：4个字节
     */
    private int shoulderAmount;

    /**
     * 谷单价：4个字节
     */
    private int offPeakPrice;

    /**
     * 谷电量：4个字节
     */
    private int offPeakCapacity;

    /**
     * 计损谷电量：4个字节
     */
    private int offPeakLossCapacity;

    /**
     * 谷金额：4个字节
     */
    private int offPeakAmount;

    /**
     * 电表总起值：5个字节
     */
    private int startMeterValue;

    /**
     * 电表总止值：5个字节
     */
    private int endMeterValue;

    /**
     * 总电量：4个字节
     */
    private int totalCapacity;

    /**
     * 计损总电量：4个字节
     */
    private int totalLossCapacity;

    /**
     * 消费金额：4个字节
     */
    private int totalAmount;

    /**
     * 电动汽车唯一标识 VIN码：17个字节
     */
    private String vin;

    /**
     * 交易标识：1个字节 0x01:app 启动 0x02:卡启动 0x04:离线卡启动 0x05: vin 码启动充电
     */
    private int startType;

    /**
     * 交易日期、时间：7个字节
     */
    private Date currentTime;

    /**
     * 停止原因：1个字节
     */
    private int endType;

    /**
     * 物理卡号：8个字节
     */
    private String cardNo;

    @Override
    public void parseBytes(byte[] bytes){
        super.parseBytes(bytes);
        transactionNo = RadixsUtil.bytesToHexString(readBytes(data,0,16));
        code = RadixsUtil.bytesToHexString(readBytes(data,16,7));
        gunNo = RadixsUtil.byteToInteger(data[23]);
        beginTime = YkcTimeUtil.toDate(readBytes(data,24,7));
        endTime = YkcTimeUtil.toDate(readBytes(data,31,7));

        sharpPrice = RadixsUtil.bytesToInteger(readBytes(data,38,4),true) / 1000;
        sharpCapacity = RadixsUtil.bytesToInteger(readBytes(data,42,4),true) / 10;
        sharpLossCapacity = RadixsUtil.bytesToInteger(readBytes(data,46,4),true) / 10;
        sharpAmount = RadixsUtil.bytesToInteger(readBytes(data,50,4),true) / 100;

        peakPrice = RadixsUtil.bytesToInteger(readBytes(data,54,4),true) / 1000;
        peakCapacity = RadixsUtil.bytesToInteger(readBytes(data,58,4),true) / 10;
        peakLossCapacity = RadixsUtil.bytesToInteger(readBytes(data,62,4),true) / 10;
        peakAmount = RadixsUtil.bytesToInteger(readBytes(data,66,4),true) / 100;

        shoulderPrice = RadixsUtil.bytesToInteger(readBytes(data,70,4),true) / 1000;
        shoulderCapacity = RadixsUtil.bytesToInteger(readBytes(data,74,4),true) / 10;
        shoulderLossCapacity = RadixsUtil.bytesToInteger(readBytes(data,78,4),true) / 10;
        shoulderAmount = RadixsUtil.bytesToInteger(readBytes(data,82,4),true) / 100;

        offPeakPrice = RadixsUtil.bytesToInteger(readBytes(data,86,4),true) / 1000;
        offPeakCapacity = RadixsUtil.bytesToInteger(readBytes(data,90,4),true) / 10;
        offPeakLossCapacity = RadixsUtil.bytesToInteger(readBytes(data,94,4),true) / 10;
        offPeakAmount = RadixsUtil.bytesToInteger(readBytes(data,98,4),true) / 100;

        startMeterValue = RadixsUtil.bytesToInteger(readBytes(data,102,5),true) / 10;
        endMeterValue = RadixsUtil.bytesToInteger(readBytes(data,107,5),true) / 10;
        totalCapacity = RadixsUtil.bytesToInteger(readBytes(data,112,4),true) / 10;
        totalLossCapacity = RadixsUtil.bytesToInteger(readBytes(data,116,4),true) / 10;
        totalAmount = RadixsUtil.bytesToInteger(readBytes(data,120,4),true) / 100;

        vin = RadixsUtil.bytesToAscii(readBytes(data,124,17)).trim();

        startType = RadixsUtil.byteToInteger(data[141]);
        currentTime = YkcTimeUtil.toDate(readBytes(data,142,7));
        endType = RadixsUtil.byteToInteger(data[149]);
        cardNo = RadixsUtil.bytesToHexString(readBytes(data,150,8));

        transactionNo = RadixsUtil.getTransactionNo(transactionNo);
        code = RadixsUtil.getCode(code);
    }
}
